<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件上传测试</title>
</head>
<body>
    <h1>文件上传测试</h1>
    <form id="uploadForm">
        <input type="file" id="fileInput" name="file" accept=".txt,.md,.pdf,.doc,.docx">
        <button type="submit">上传</button>
    </form>
    <div id="result"></div>

    <script>
        document.getElementById('uploadForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const fileInput = document.getElementById('fileInput');
            const file = fileInput.files[0];
            
            if (!file) {
                alert('请选择文件');
                return;
            }
            
            const formData = new FormData();
            formData.append('file', file);
            
            try {
                const response = await fetch('http://localhost:8080/api/knowledge/upload', {
                    method: 'POST',
                    body: formData
                });
                
                const resultDiv = document.getElementById('result');
                
                if (response.ok) {
                    const data = await response.json();
                    resultDiv.innerHTML = `<p style="color: green;">上传成功！文档ID: ${data.id}</p>`;
                } else {
                    const errorText = await response.text();
                    resultDiv.innerHTML = `<p style="color: red;">上传失败！状态码: ${response.status}, 错误: ${errorText}</p>`;
                }
            } catch (error) {
                document.getElementById('result').innerHTML = `<p style="color: red;">请求失败: ${error.message}</p>`;
            }
        });
    </script>
</body>
</html> 